        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>DistanceJoint class / box2d Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="box2d" data-type="DistanceJoint">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../box2d.html">box2d</a> &rsaquo; <a href="../box2d/DistanceJoint.html">DistanceJoint</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>DistanceJoint</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<pre class="source">
class DistanceJoint extends Joint {
 final vec2 localAnchor1;
 final vec2 localAnchor2;
 final vec2 u;
 num impulse;

 /** Effective mass for the constraint. */
 num mass;
 num length;
 num frequencyHz;
 num dampingRatio;
 num gamma;
 num bias;

 DistanceJoint(DistanceJointDef def) :
   super(def),
   localAnchor1 = new vec2.copy(def.localAnchorA),
   localAnchor2 = new vec2.copy(def.localAnchorB),
   length = def.length,
   impulse = 0.0,
   u = new vec2.zero(),
   frequencyHz = def.frequencyHz,
   dampingRatio = def.dampingRatio,
   gamma = 0.0,
   bias = 0.0 { }

 void getAnchorA(vec2 argOut) {
   bodyA.getWorldPointToOut(localAnchor1, argOut);
 }

 void getAnchorB(vec2 argOut) {
   bodyB.getWorldPointToOut(localAnchor2, argOut);
 }

 void getReactionForce(num inv_dt, vec2 argOut) {
   argOut.x = impulse * u.x * inv_dt;
   argOut.y = impulse * u.y * inv_dt;
 }

 num getReactionTorque(num inv_dt) {
   return 0.0;
 }

 void initVelocityConstraints(TimeStep time_step) {
   final Body b1 = bodyA;
   final Body b2 = bodyB;

   vec2 r1 = new vec2.zero();
   vec2 r2 = new vec2.zero();

   // Compute the effective mass matrix.
   r1.copyFrom(localAnchor1).sub(b1.localCenter);
   r2.copyFrom(localAnchor2).sub(b2.localCenter);
   b1.originTransform.rotation.transform(r1);
   b2.originTransform.rotation.transform(r2);

   u.copyFrom(b2.sweep.center).add(r2).sub(b1.sweep.center).sub(r1);

   // Handle singularity.
   num len = u.length;
   if (len &gt; Settings.LINEAR_SLOP) {
     u.scale(1.0 / len);
   } else {
     u.splat(0.0);
   }

   num cr1u = cross(r1, u);
   num cr2u = cross(r2, u);

   num invMass = b1.invMass + b1.invInertia * cr1u * cr1u + b2.invMass
       + b2.invInertia * cr2u * cr2u;
   assert (invMass &gt; Settings.EPSILON);
   mass = 1.0 / invMass;

   if (frequencyHz &gt; 0.0) {
     num C = len - length;

     // Frequency
     num omega = MathBox.TWO_PI * frequencyHz;

     // Damping coefficient
     num d = 2.0 * mass * dampingRatio * omega;

     // Spring stiffness
     num k = mass * omega * omega;

     // magic formulas
     gamma = time_step.dt * (d + time_step.dt * k);
     gamma = gamma != 0.0 ? 1.0 / gamma : 0.0;
     bias = C * time_step.dt * k * gamma;

     mass = invMass + gamma;
     mass = mass != 0.0 ? 1.0 / mass : 0.0;
   }

   if (time_step.warmStarting) {
     // Scale the impulse to support a variable time time_step.
     impulse *= time_step.dtRatio;

     vec2 P = new vec2.zero();
     P.copyFrom(u).scale(impulse);

     b1.linearVelocity.x -= b1.invMass * P.x;
     b1.linearVelocity.y -= b1.invMass * P.y;
     b1.angularVelocity -= b1.invInertia * cross(r1, P);

     b2.linearVelocity.x += b2.invMass * P.x;
     b2.linearVelocity.y += b2.invMass * P.y;
     b2.angularVelocity += b2.invInertia * cross(r2, P);
   } else {
     impulse = 0.0;
   }
 }

 void solveVelocityConstraints(TimeStep time_step) {
   final Body b1 = bodyA;
   final Body b2 = bodyB;

   final vec2 r1 = localAnchor1 - b1.localCenter;
   final vec2 r2 = localAnchor2 - b2.localCenter;

   b1.originTransform.rotation.transform(r1);
   b2.originTransform.rotation.transform(r2);

   final v1 = cross(b1.angularVelocity, r1);
   final v2 = cross(b2.angularVelocity, r2);
   v1.add(b1.linearVelocity);
   v2.add(b2.linearVelocity);

   num Cdot = dot(u, v2.sub(v1));

   num imp = -mass * (Cdot + bias + gamma * impulse);
   impulse += imp;

   num Px = imp * u.x;
   num Py = imp * u.y;
   b1.linearVelocity.x -= b1.invMass * Px;
   b1.linearVelocity.y -= b1.invMass * Py;
   b1.angularVelocity -= b1.invInertia * (r1.x * Py - r1.y * Px);
   b2.linearVelocity.x += b2.invMass * Px;
   b2.linearVelocity.y += b2.invMass * Py;
   b2.angularVelocity += b2.invInertia * (r2.x * Py - r2.y * Px);
 }

 bool solvePositionConstraints(num baumgarte) {
   if (frequencyHz &gt; 0.0) {
     return true;
   }

   final b1 = bodyA;
   final b2 = bodyB;

   final vec2 r1 = localAnchor1 - b1.localCenter;
   final vec2 r2 = localAnchor2 - b2.localCenter;

   b1.originTransform.rotation.transform(r1);
   b2.originTransform.rotation.transform(r2);

   final vec2 d = b2.sweep.center + r2 - (b1.sweep.center + r1);

   num len = d.length;
   d.normalize();
   num C = len - length;
   C = clamp(C, -Settings.MAX_LINEAR_CORRECTION, Settings.MAX_LINEAR_CORRECTION);

   num imp = -mass * C;
   u.copyFrom(d);
   num Px = imp * u.x;
   num Py = imp * u.y;

   b1.sweep.center.x -= b1.invMass * Px;
   b1.sweep.center.y -= b1.invMass * Py;
   b1.sweep.angle -= b1.invInertia * (r1.x * Py - r1.y * Px);

   b2.sweep.center.x += b2.invMass * Px;
   b2.sweep.center.y += b2.invMass * Py;
   b2.sweep.angle += b2.invInertia * (r2.x * Py - r2.y * Px);

   b1.synchronizeTransform();
   b2.synchronizeTransform();

   return C.abs() &lt; Settings.LINEAR_SLOP;
 }
}
</pre>
</div>
<h3>Extends</h3>
<p>
<span class="type-box"><span class="icon-class"></span><a href="../box2d/Joint.html">Joint</a></span>&nbsp;&gt;&nbsp;<span class="type-box"><span class="icon-class"></span><strong>DistanceJoint</strong></span></p>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="DistanceJoint">
<button class="show-code">Code</button>
new <strong>DistanceJoint</strong>(<a href="../box2d/DistanceJointDef.html">DistanceJointDef</a> def) <a class="anchor-link" href="#DistanceJoint"
              title="Permalink to DistanceJoint.DistanceJoint">#</a></h4>
<div class="doc">
<pre class="source">
DistanceJoint(DistanceJointDef def) :
 super(def),
 localAnchor1 = new vec2.copy(def.localAnchorA),
 localAnchor2 = new vec2.copy(def.localAnchorB),
 length = def.length,
 impulse = 0.0,
 u = new vec2.zero(),
 frequencyHz = def.frequencyHz,
 dampingRatio = def.dampingRatio,
 gamma = 0.0,
 bias = 0.0 { }
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="field inherited"><h4 id="active">
<button class="show-code">Code</button>
final bool         <strong>active</strong> <a class="anchor-link"
            href="#active"
            title="Permalink to DistanceJoint.active">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<p>Short-cut function to determine if either body is inactive. </p>
<pre class="source">
bool get active =&gt; bodyA.active &amp;&amp; bodyB.active;
</pre>
</div>
</div>
<div class="field"><h4 id="bias">
<button class="show-code">Code</button>
num         <strong>bias</strong> <a class="anchor-link"
            href="#bias"
            title="Permalink to DistanceJoint.bias">#</a>
        </h4>
        <div class="doc">
<pre class="source">
bias
</pre>
</div>
</div>
<div class="field inherited"><h4 id="bodyA">
<button class="show-code">Code</button>
<a href="../box2d/Body.html">Body</a>         <strong>bodyA</strong> <a class="anchor-link"
            href="#bodyA"
            title="Permalink to DistanceJoint.bodyA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
bodyA
</pre>
</div>
</div>
<div class="field inherited"><h4 id="bodyB">
<button class="show-code">Code</button>
<a href="../box2d/Body.html">Body</a>         <strong>bodyB</strong> <a class="anchor-link"
            href="#bodyB"
            title="Permalink to DistanceJoint.bodyB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
bodyB
</pre>
</div>
</div>
<div class="field inherited"><h4 id="collideConnected">
<button class="show-code">Code</button>
bool         <strong>collideConnected</strong> <a class="anchor-link"
            href="#collideConnected"
            title="Permalink to DistanceJoint.collideConnected">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
collideConnected
</pre>
</div>
</div>
<div class="field"><h4 id="dampingRatio">
<button class="show-code">Code</button>
num         <strong>dampingRatio</strong> <a class="anchor-link"
            href="#dampingRatio"
            title="Permalink to DistanceJoint.dampingRatio">#</a>
        </h4>
        <div class="doc">
<pre class="source">
dampingRatio
</pre>
</div>
</div>
<div class="field inherited"><h4 id="edgeA">
<button class="show-code">Code</button>
<a href="../box2d/JointEdge.html">JointEdge</a>         <strong>edgeA</strong> <a class="anchor-link"
            href="#edgeA"
            title="Permalink to DistanceJoint.edgeA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
edgeA
</pre>
</div>
</div>
<div class="field inherited"><h4 id="edgeB">
<button class="show-code">Code</button>
<a href="../box2d/JointEdge.html">JointEdge</a>         <strong>edgeB</strong> <a class="anchor-link"
            href="#edgeB"
            title="Permalink to DistanceJoint.edgeB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
edgeB
</pre>
</div>
</div>
<div class="field"><h4 id="frequencyHz">
<button class="show-code">Code</button>
num         <strong>frequencyHz</strong> <a class="anchor-link"
            href="#frequencyHz"
            title="Permalink to DistanceJoint.frequencyHz">#</a>
        </h4>
        <div class="doc">
<pre class="source">
frequencyHz
</pre>
</div>
</div>
<div class="field"><h4 id="gamma">
<button class="show-code">Code</button>
num         <strong>gamma</strong> <a class="anchor-link"
            href="#gamma"
            title="Permalink to DistanceJoint.gamma">#</a>
        </h4>
        <div class="doc">
<pre class="source">
gamma
</pre>
</div>
</div>
<div class="field"><h4 id="impulse">
<button class="show-code">Code</button>
num         <strong>impulse</strong> <a class="anchor-link"
            href="#impulse"
            title="Permalink to DistanceJoint.impulse">#</a>
        </h4>
        <div class="doc">
<pre class="source">
impulse
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invIA">
<button class="show-code">Code</button>
num         <strong>invIA</strong> <a class="anchor-link"
            href="#invIA"
            title="Permalink to DistanceJoint.invIA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
invIA
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invIB">
<button class="show-code">Code</button>
num         <strong>invIB</strong> <a class="anchor-link"
            href="#invIB"
            title="Permalink to DistanceJoint.invIB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
invIB
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invMassA">
<button class="show-code">Code</button>
num         <strong>invMassA</strong> <a class="anchor-link"
            href="#invMassA"
            title="Permalink to DistanceJoint.invMassA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
invMassA
</pre>
</div>
</div>
<div class="field inherited"><h4 id="invMassB">
<button class="show-code">Code</button>
num         <strong>invMassB</strong> <a class="anchor-link"
            href="#invMassB"
            title="Permalink to DistanceJoint.invMassB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
invMassB
</pre>
</div>
</div>
<div class="field inherited"><h4 id="islandFlag">
<button class="show-code">Code</button>
bool         <strong>islandFlag</strong> <a class="anchor-link"
            href="#islandFlag"
            title="Permalink to DistanceJoint.islandFlag">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
islandFlag
</pre>
</div>
</div>
<div class="field"><h4 id="length">
<button class="show-code">Code</button>
num         <strong>length</strong> <a class="anchor-link"
            href="#length"
            title="Permalink to DistanceJoint.length">#</a>
        </h4>
        <div class="doc">
<pre class="source">
length
</pre>
</div>
</div>
<div class="field"><h4 id="localAnchor1">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>localAnchor1</strong> <a class="anchor-link"
            href="#localAnchor1"
            title="Permalink to DistanceJoint.localAnchor1">#</a>
        </h4>
        <div class="doc">
<pre class="source">
localAnchor1
</pre>
</div>
</div>
<div class="field"><h4 id="localAnchor2">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>localAnchor2</strong> <a class="anchor-link"
            href="#localAnchor2"
            title="Permalink to DistanceJoint.localAnchor2">#</a>
        </h4>
        <div class="doc">
<pre class="source">
localAnchor2
</pre>
</div>
</div>
<div class="field inherited"><h4 id="localCenterA">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>localCenterA</strong> <a class="anchor-link"
            href="#localCenterA"
            title="Permalink to DistanceJoint.localCenterA">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
localCenterA
</pre>
</div>
</div>
<div class="field inherited"><h4 id="localCenterB">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>localCenterB</strong> <a class="anchor-link"
            href="#localCenterB"
            title="Permalink to DistanceJoint.localCenterB">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
localCenterB
</pre>
</div>
</div>
<div class="field"><h4 id="mass">
<button class="show-code">Code</button>
num         <strong>mass</strong> <a class="anchor-link"
            href="#mass"
            title="Permalink to DistanceJoint.mass">#</a>
        </h4>
        <div class="doc">
<pre class="source">
mass
</pre>
</div>
</div>
<div class="field inherited"><h4 id="type">
<button class="show-code">Code</button>
int         <strong>type</strong> <a class="anchor-link"
            href="#type"
            title="Permalink to DistanceJoint.type">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
type
</pre>
</div>
</div>
<div class="field"><h4 id="u">
<button class="show-code">Code</button>
final <a href="../vector_math/vec2.html">vec2</a>         <strong>u</strong> <a class="anchor-link"
            href="#u"
            title="Permalink to DistanceJoint.u">#</a>
        </h4>
        <div class="doc">
<pre class="source">
u
</pre>
</div>
</div>
<div class="field inherited"><h4 id="userData">
<button class="show-code">Code</button>
Object         <strong>userData</strong> <a class="anchor-link"
            href="#userData"
            title="Permalink to DistanceJoint.userData">#</a>
        </h4>
        <div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<pre class="source">
userData
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method inherited"><h4 id="destructor">
<button class="show-code">Code</button>
void <strong>destructor</strong>() <a class="anchor-link" href="#destructor"
              title="Permalink to DistanceJoint.destructor">#</a></h4>
<div class="inherited-from">inherited from <a href="../box2d/Joint.html">Joint</a> </div><div class="doc">
<p>Override to handle destruction of joint. </p>
<pre class="source">
void destructor() { }
</pre>
</div>
</div>
<div class="method"><h4 id="getAnchorA">
<button class="show-code">Code</button>
void <strong>getAnchorA</strong>(<a href="../vector_math/vec2.html">vec2</a> argOut) <a class="anchor-link" href="#getAnchorA"
              title="Permalink to DistanceJoint.getAnchorA">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Get the anchor point on bodyA in world coordinates. </p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d/Joint.html">Joint</a> </div></div>
<pre class="source">
void getAnchorA(vec2 argOut) {
 bodyA.getWorldPointToOut(localAnchor1, argOut);
}
</pre>
</div>
</div>
<div class="method"><h4 id="getAnchorB">
<button class="show-code">Code</button>
void <strong>getAnchorB</strong>(<a href="../vector_math/vec2.html">vec2</a> argOut) <a class="anchor-link" href="#getAnchorB"
              title="Permalink to DistanceJoint.getAnchorB">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Get the anchor point on bodyB in world coordinates. </p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d/Joint.html">Joint</a> </div></div>
<pre class="source">
void getAnchorB(vec2 argOut) {
 bodyB.getWorldPointToOut(localAnchor2, argOut);
}
</pre>
</div>
</div>
<div class="method"><h4 id="getReactionForce">
<button class="show-code">Code</button>
void <strong>getReactionForce</strong>(num inv_dt, <a href="../vector_math/vec2.html">vec2</a> argOut) <a class="anchor-link" href="#getReactionForce"
              title="Permalink to DistanceJoint.getReactionForce">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Get the reaction force on body2 at the joint anchor in Newtons. </p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d/Joint.html">Joint</a> </div></div>
<pre class="source">
void getReactionForce(num inv_dt, vec2 argOut) {
 argOut.x = impulse * u.x * inv_dt;
 argOut.y = impulse * u.y * inv_dt;
}
</pre>
</div>
</div>
<div class="method"><h4 id="getReactionTorque">
<button class="show-code">Code</button>
num <strong>getReactionTorque</strong>(num inv_dt) <a class="anchor-link" href="#getReactionTorque"
              title="Permalink to DistanceJoint.getReactionTorque">#</a></h4>
<div class="doc">
<div class="inherited">
<p>Get the reaction torque on body2 in N*m. </p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d/Joint.html">Joint</a> </div></div>
<pre class="source">
num getReactionTorque(num inv_dt) {
 return 0.0;
}
</pre>
</div>
</div>
<div class="method"><h4 id="initVelocityConstraints">
<button class="show-code">Code</button>
void <strong>initVelocityConstraints</strong>(<a href="../box2d/TimeStep.html">TimeStep</a> time_step) <a class="anchor-link" href="#initVelocityConstraints"
              title="Permalink to DistanceJoint.initVelocityConstraints">#</a></h4>
<div class="doc">
<pre class="source">
void initVelocityConstraints(TimeStep time_step) {
 final Body b1 = bodyA;
 final Body b2 = bodyB;

 vec2 r1 = new vec2.zero();
 vec2 r2 = new vec2.zero();

 // Compute the effective mass matrix.
 r1.copyFrom(localAnchor1).sub(b1.localCenter);
 r2.copyFrom(localAnchor2).sub(b2.localCenter);
 b1.originTransform.rotation.transform(r1);
 b2.originTransform.rotation.transform(r2);

 u.copyFrom(b2.sweep.center).add(r2).sub(b1.sweep.center).sub(r1);

 // Handle singularity.
 num len = u.length;
 if (len &gt; Settings.LINEAR_SLOP) {
   u.scale(1.0 / len);
 } else {
   u.splat(0.0);
 }

 num cr1u = cross(r1, u);
 num cr2u = cross(r2, u);

 num invMass = b1.invMass + b1.invInertia * cr1u * cr1u + b2.invMass
     + b2.invInertia * cr2u * cr2u;
 assert (invMass &gt; Settings.EPSILON);
 mass = 1.0 / invMass;

 if (frequencyHz &gt; 0.0) {
   num C = len - length;

   // Frequency
   num omega = MathBox.TWO_PI * frequencyHz;

   // Damping coefficient
   num d = 2.0 * mass * dampingRatio * omega;

   // Spring stiffness
   num k = mass * omega * omega;

   // magic formulas
   gamma = time_step.dt * (d + time_step.dt * k);
   gamma = gamma != 0.0 ? 1.0 / gamma : 0.0;
   bias = C * time_step.dt * k * gamma;

   mass = invMass + gamma;
   mass = mass != 0.0 ? 1.0 / mass : 0.0;
 }

 if (time_step.warmStarting) {
   // Scale the impulse to support a variable time time_step.
   impulse *= time_step.dtRatio;

   vec2 P = new vec2.zero();
   P.copyFrom(u).scale(impulse);

   b1.linearVelocity.x -= b1.invMass * P.x;
   b1.linearVelocity.y -= b1.invMass * P.y;
   b1.angularVelocity -= b1.invInertia * cross(r1, P);

   b2.linearVelocity.x += b2.invMass * P.x;
   b2.linearVelocity.y += b2.invMass * P.y;
   b2.angularVelocity += b2.invInertia * cross(r2, P);
 } else {
   impulse = 0.0;
 }
}
</pre>
</div>
</div>
<div class="method"><h4 id="solvePositionConstraints">
<button class="show-code">Code</button>
bool <strong>solvePositionConstraints</strong>(num baumgarte) <a class="anchor-link" href="#solvePositionConstraints"
              title="Permalink to DistanceJoint.solvePositionConstraints">#</a></h4>
<div class="doc">
<div class="inherited">
<p>This returns true if the position errors are within tolerance. </p>
<div class="docs-inherited-from">docs inherited from <a href="../box2d/Joint.html">Joint</a> </div></div>
<pre class="source">
bool solvePositionConstraints(num baumgarte) {
 if (frequencyHz &gt; 0.0) {
   return true;
 }

 final b1 = bodyA;
 final b2 = bodyB;

 final vec2 r1 = localAnchor1 - b1.localCenter;
 final vec2 r2 = localAnchor2 - b2.localCenter;

 b1.originTransform.rotation.transform(r1);
 b2.originTransform.rotation.transform(r2);

 final vec2 d = b2.sweep.center + r2 - (b1.sweep.center + r1);

 num len = d.length;
 d.normalize();
 num C = len - length;
 C = clamp(C, -Settings.MAX_LINEAR_CORRECTION, Settings.MAX_LINEAR_CORRECTION);

 num imp = -mass * C;
 u.copyFrom(d);
 num Px = imp * u.x;
 num Py = imp * u.y;

 b1.sweep.center.x -= b1.invMass * Px;
 b1.sweep.center.y -= b1.invMass * Py;
 b1.sweep.angle -= b1.invInertia * (r1.x * Py - r1.y * Px);

 b2.sweep.center.x += b2.invMass * Px;
 b2.sweep.center.y += b2.invMass * Py;
 b2.sweep.angle += b2.invInertia * (r2.x * Py - r2.y * Px);

 b1.synchronizeTransform();
 b2.synchronizeTransform();

 return C.abs() &lt; Settings.LINEAR_SLOP;
}
</pre>
</div>
</div>
<div class="method"><h4 id="solveVelocityConstraints">
<button class="show-code">Code</button>
void <strong>solveVelocityConstraints</strong>(<a href="../box2d/TimeStep.html">TimeStep</a> time_step) <a class="anchor-link" href="#solveVelocityConstraints"
              title="Permalink to DistanceJoint.solveVelocityConstraints">#</a></h4>
<div class="doc">
<pre class="source">
void solveVelocityConstraints(TimeStep time_step) {
 final Body b1 = bodyA;
 final Body b2 = bodyB;

 final vec2 r1 = localAnchor1 - b1.localCenter;
 final vec2 r2 = localAnchor2 - b2.localCenter;

 b1.originTransform.rotation.transform(r1);
 b2.originTransform.rotation.transform(r2);

 final v1 = cross(b1.angularVelocity, r1);
 final v2 = cross(b2.angularVelocity, r2);
 v1.add(b1.linearVelocity);
 v2.add(b2.linearVelocity);

 num Cdot = dot(u, v2.sub(v1));

 num imp = -mass * (Cdot + bias + gamma * impulse);
 impulse += imp;

 num Px = imp * u.x;
 num Py = imp * u.y;
 b1.linearVelocity.x -= b1.invMass * Px;
 b1.linearVelocity.y -= b1.invMass * Py;
 b1.angularVelocity -= b1.invInertia * (r1.x * Py - r1.y * Px);
 b2.linearVelocity.x += b2.invMass * Px;
 b2.linearVelocity.y += b2.invMass * Py;
 b2.angularVelocity += b2.invInertia * (r2.x * Py - r2.y * Px);
}
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
